package com.icss.th.question.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.icss.th.common.util.SecureUtil;
import com.icss.th.common.util.ServletUtil;
import com.icss.th.question.service.OptionService;

/**
 * Servlet implementation class CorrectServlet
 */
@WebServlet("/correct")
public class CorrectServlet extends HttpServlet 
{
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		String content = request.getParameter("content");
		String examId = request.getParameter("examId");
		String optionType = request.getParameter("optionType");
		String ip = ServletUtil.getUserIp(request);
		
		try 
		{
			OptionService.saveCorrect(content, SecureUtil.decryptPassword(examId), optionType, ip);
		}
		catch (Exception e)
		{
			throw new ServletException(e.getMessage(), e);
		}
	}
}
